// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file LogEntryTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen.
 */

#include <ddspipe_core/types/logging/LogEntryTypeObjectSupport.hpp>

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>

#include <ddspipe_core/types/logging/LogEntry.hpp>


using namespace eprosima::fastdds::dds::xtypes;

void register_Kind_type_identifier(
        TypeIdentifierPair& type_ids_Kind)
{
    ReturnCode_t return_code_Kind {eprosima::fastdds::dds::RETCODE_OK};
    return_code_Kind =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "Kind", type_ids_Kind);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_Kind)
    {
        EnumTypeFlag enum_flags_Kind = 0;
        BitBound bit_bound_Kind = 32;
        CommonEnumeratedHeader common_Kind = TypeObjectUtils::build_common_enumerated_header(bit_bound_Kind);
        QualifiedTypeName type_name_Kind = "Kind";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_Kind;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_Kind;
        CompleteTypeDetail detail_Kind = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_Kind, ann_custom_Kind, type_name_Kind.to_string());
        CompleteEnumeratedHeader header_Kind = TypeObjectUtils::build_complete_enumerated_header(common_Kind, detail_Kind);
        CompleteEnumeratedLiteralSeq literal_seq_Kind;
        {
            EnumeratedLiteralFlag flags_Info = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_Info = TypeObjectUtils::build_common_enumerated_literal(0, flags_Info);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_Info;
            ann_custom_Kind.reset();
            MemberName name_Info = "Info";
            CompleteMemberDetail detail_Info = TypeObjectUtils::build_complete_member_detail(name_Info, member_ann_builtin_Info, ann_custom_Kind);
            CompleteEnumeratedLiteral literal_Info = TypeObjectUtils::build_complete_enumerated_literal(common_Info, detail_Info);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_Kind, literal_Info);
        }
        {
            EnumeratedLiteralFlag flags_Warning = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_Warning = TypeObjectUtils::build_common_enumerated_literal(1, flags_Warning);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_Warning;
            ann_custom_Kind.reset();
            MemberName name_Warning = "Warning";
            CompleteMemberDetail detail_Warning = TypeObjectUtils::build_complete_member_detail(name_Warning, member_ann_builtin_Warning, ann_custom_Kind);
            CompleteEnumeratedLiteral literal_Warning = TypeObjectUtils::build_complete_enumerated_literal(common_Warning, detail_Warning);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_Kind, literal_Warning);
        }
        {
            EnumeratedLiteralFlag flags_Error = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_Error = TypeObjectUtils::build_common_enumerated_literal(2, flags_Error);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_Error;
            ann_custom_Kind.reset();
            MemberName name_Error = "Error";
            CompleteMemberDetail detail_Error = TypeObjectUtils::build_complete_member_detail(name_Error, member_ann_builtin_Error, ann_custom_Kind);
            CompleteEnumeratedLiteral literal_Error = TypeObjectUtils::build_complete_enumerated_literal(common_Error, detail_Error);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_Kind, literal_Error);
        }
        CompleteEnumeratedType enumerated_type_Kind = TypeObjectUtils::build_complete_enumerated_type(enum_flags_Kind, header_Kind,
                literal_seq_Kind);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_Kind, type_name_Kind.to_string(), type_ids_Kind))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                "Kind already registered in TypeObjectRegistry for a different type.");
        }
    }
}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_LogEntry_type_identifier(
        TypeIdentifierPair& type_ids_LogEntry)
{

    ReturnCode_t return_code_LogEntry {eprosima::fastdds::dds::RETCODE_OK};
    return_code_LogEntry =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "LogEntry", type_ids_LogEntry);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_LogEntry)
    {
        StructTypeFlag struct_flags_LogEntry = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_LogEntry = "LogEntry";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_LogEntry;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_LogEntry;
        CompleteTypeDetail detail_LogEntry = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_LogEntry, ann_custom_LogEntry, type_name_LogEntry.to_string());
        CompleteStructHeader header_LogEntry;
        header_LogEntry = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_LogEntry);
        CompleteStructMemberSeq member_seq_LogEntry;
        {
            TypeIdentifierPair type_ids_event;
            ReturnCode_t return_code_event {eprosima::fastdds::dds::RETCODE_OK};
            return_code_event =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_event);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_event)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "event Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_event = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, true, false);
            MemberId member_id_event = 0x00000000;
            bool common_event_ec {false};
            CommonStructMember common_event {TypeObjectUtils::build_common_struct_member(member_id_event, member_flags_event, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_event, common_event_ec))};
            if (!common_event_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure event member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_event = "event";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_event;
            ann_custom_LogEntry.reset();
            AppliedAnnotationSeq tmp_ann_custom_event;
            eprosima::fastcdr::optional<std::string> unit_event;
            eprosima::fastcdr::optional<AnnotationParameterValue> min_event;
            eprosima::fastcdr::optional<AnnotationParameterValue> max_event;
            eprosima::fastcdr::optional<std::string> hash_id_event;
            if (unit_event.has_value() || min_event.has_value() || max_event.has_value() || hash_id_event.has_value())
            {
                member_ann_builtin_event = TypeObjectUtils::build_applied_builtin_member_annotations(unit_event, min_event, max_event, hash_id_event);
            }
            if (!tmp_ann_custom_event.empty())
            {
                ann_custom_LogEntry = tmp_ann_custom_event;
            }
            CompleteMemberDetail detail_event = TypeObjectUtils::build_complete_member_detail(name_event, member_ann_builtin_event, ann_custom_LogEntry);
            CompleteStructMember member_event = TypeObjectUtils::build_complete_struct_member(common_event, detail_event);
            TypeObjectUtils::add_complete_struct_member(member_seq_LogEntry, member_event);
        }
        {
            TypeIdentifierPair type_ids_kind;
            ReturnCode_t return_code_kind {eprosima::fastdds::dds::RETCODE_OK};
            return_code_kind =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "Kind", type_ids_kind);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_kind)
            {
            ::register_Kind_type_identifier(type_ids_kind);
            }
            StructMemberFlag member_flags_kind = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_kind = 0x00000001;
            bool common_kind_ec {false};
            CommonStructMember common_kind {TypeObjectUtils::build_common_struct_member(member_id_kind, member_flags_kind, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_kind, common_kind_ec))};
            if (!common_kind_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure kind member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_kind = "kind";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_kind;
            ann_custom_LogEntry.reset();
            CompleteMemberDetail detail_kind = TypeObjectUtils::build_complete_member_detail(name_kind, member_ann_builtin_kind, ann_custom_LogEntry);
            CompleteStructMember member_kind = TypeObjectUtils::build_complete_struct_member(common_kind, detail_kind);
            TypeObjectUtils::add_complete_struct_member(member_seq_LogEntry, member_kind);
        }
        {
            TypeIdentifierPair type_ids_category;
            ReturnCode_t return_code_category {eprosima::fastdds::dds::RETCODE_OK};
            return_code_category =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_category);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_category)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_category))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_category = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_category = 0x00000002;
            bool common_category_ec {false};
            CommonStructMember common_category {TypeObjectUtils::build_common_struct_member(member_id_category, member_flags_category, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_category, common_category_ec))};
            if (!common_category_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure category member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_category = "category";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_category;
            ann_custom_LogEntry.reset();
            CompleteMemberDetail detail_category = TypeObjectUtils::build_complete_member_detail(name_category, member_ann_builtin_category, ann_custom_LogEntry);
            CompleteStructMember member_category = TypeObjectUtils::build_complete_struct_member(common_category, detail_category);
            TypeObjectUtils::add_complete_struct_member(member_seq_LogEntry, member_category);
        }
        {
            TypeIdentifierPair type_ids_message;
            ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK};
            return_code_message =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_message);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_message)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_message))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_message = 0x00000003;
            bool common_message_ec {false};
            CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))};
            if (!common_message_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_message = "message";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_message;
            ann_custom_LogEntry.reset();
            CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_LogEntry);
            CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message);
            TypeObjectUtils::add_complete_struct_member(member_seq_LogEntry, member_message);
        }
        {
            TypeIdentifierPair type_ids_timestamp;
            ReturnCode_t return_code_timestamp {eprosima::fastdds::dds::RETCODE_OK};
            return_code_timestamp =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "anonymous_string_unbounded", type_ids_timestamp);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_timestamp)
            {
                {
                    SBound bound = 0;
                    StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
                    if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                            TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
                            "anonymous_string_unbounded", type_ids_timestamp))
                    {
                        EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                            "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
                    }
                }
            }
            StructMemberFlag member_flags_timestamp = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_timestamp = 0x00000004;
            bool common_timestamp_ec {false};
            CommonStructMember common_timestamp {TypeObjectUtils::build_common_struct_member(member_id_timestamp, member_flags_timestamp, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_timestamp, common_timestamp_ec))};
            if (!common_timestamp_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure timestamp member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_timestamp = "timestamp";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_timestamp;
            ann_custom_LogEntry.reset();
            CompleteMemberDetail detail_timestamp = TypeObjectUtils::build_complete_member_detail(name_timestamp, member_ann_builtin_timestamp, ann_custom_LogEntry);
            CompleteStructMember member_timestamp = TypeObjectUtils::build_complete_struct_member(common_timestamp, detail_timestamp);
            TypeObjectUtils::add_complete_struct_member(member_seq_LogEntry, member_timestamp);
        }
        CompleteStructType struct_type_LogEntry = TypeObjectUtils::build_complete_struct_type(struct_flags_LogEntry, header_LogEntry, member_seq_LogEntry);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_LogEntry, type_name_LogEntry.to_string(), type_ids_LogEntry))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "LogEntry already registered in TypeObjectRegistry for a different type.");
        }
    }
}

